﻿using DoNet.Handlers.Commands;
using DoNet.System.IServices;
using MediatR;

namespace DoNet.Handlers.Handlers
{
    /// <summary>
    /// 访问日志
    /// </summary>
    internal class VisitLogCommandHandler : IRequestHandler<VisitLogCommand, bool>
    {
        private readonly IVisitLogService _visitLogService;

        public VisitLogCommandHandler(IVisitLogService visitLogService)
        {
            _visitLogService = visitLogService;
        }

        public async Task<bool> Handle(VisitLogCommand request, CancellationToken cancellationToken)
        {
            int row = 0;
            var visitLog = request.VisitLogInput;
            if (visitLog != null)
            {
                row = await _visitLogService.InsertAsync(visitLog);
            }
            return row > 0;
        }
    }
}
